<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'zhuce.jsp' starting page</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	   	<script type="text/javascript">
		function checknum1() { 
	if (!checkIdcard(formname.userCarid.value)){
		return false;
	}
	if(!check(formname.pone.value)){
		return false;
	}
    }

	  //checkaddress()
        function checkaddress(){
    var temp= document.getElementById("address");
	var partten = /^[\u4E00-\u9FA5]+$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的地址！');
	address.focus();
		return false ;
	}else{
		return false ;
	}
}
}
  //checkphone()
      function checkphone(){
    var temp= document.getElementById("phone");
	var partten = /^((\(\d{3}\))|(\d{3}\-))?13[0-9]\d{8}|15[0-9]\d{8}|189\d{8}$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的电话！');
	phone.focus();
		return false ;
	}else{
		return false ;
	}
}
}
  //checkemail()
    function checkemail(){
    var temp= document.getElementById("email");
	var partten = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的email！');
	email.focus();
		return false ;
	}else{
		return false ;
	}
}
}
  
  //验证name
  function checkname(){
    var temp= document.getElementById("name");
	var partten = /^[\u4E00-\u9FA5]+$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的name，只能是汉字！');
	name.focus();
		return false ;
	}else{
		return false ;
	}
}
}
  //验证pass
function checkpass(){
    var temp= document.getElementById("pass");
	var partten = /^[A-Za-z0-9]+$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的pass,只能是数字和字母！');
	pass.focus();
		return false ;
	}else{
		return false ;
	}
}
}
  //验证id
function checkid(){
    var temp= document.getElementById("id");
	var partten = /^[A-Za-z]+$/;
	if(temp.value!=""){
	if(!partten.test(temp.value)){
	alert('提示:请输入有效的id,只能是字母！');
	id.focus();
		return false ;
	}else{
		return false ;
	}
}
}
  
	//验证电话
	function check(num){
    if(!(/(^(\d{3,4}-)?\d{7,8})$|(^1[3|4|5|8][0-9]{9})/.test(num))){
    	alert("请输入正确的电话");
        return false;
    }else{
        return true;
    }
   }
 function checkIdcard(num){
    num = num.toUpperCase();
    if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num)))
    {
        alert('输入的身份证号长度不对，或者号码不符合规定！\n15位号码应全为数字，18位号码末位可以为数字或X。');
        return false;
    }
 
    var len, re;
    len = num.length;
    if (len == 15)
    {
        re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
        var arrSplit = num.match(re);
 
       
        var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
        var bGoodDay;
        bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
        if (!bGoodDay)
        {
            alert('输入的身份证号里出生日期不对！');
            return false;
        }
        else
        {
              
                var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
                var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
                var nTemp = 0, i;
                num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
                for(i = 0; i < 17; i ++)
                {
                    nTemp += num.substr(i, 1) * arrInt[i];
                }
                num += arrCh[nTemp % 11];
                return true;
        }
    }
    if (len == 18)
    {
        re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
        var arrSplit = num.match(re);
 
        //检查生日日期是否正确
        var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
        var bGoodDay;
        bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
        if (!bGoodDay)
        {
            alert('输入的身份证号里出生日期不对！');
            return false;
        }
    else
    {
        //检验18位身份证的校验码是否正确。
        //校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
        var valnum;
        var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
        var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
        var nTemp = 0, i;
        for(i = 0; i < 17; i ++)
        {
            nTemp += num.substr(i, 1) * arrInt[i];
        }
        valnum = arrCh[nTemp % 11];
        if (valnum != num.substr(17, 1))
        {
            alert('18位身份证的校验码不正确！应该为：' + valnum);
            return false;
        }
        return true;
    }
    }
    return false;
}
	</script>
<style>
    body {
	margin: 0px;
	padding: 0px;
	background-color: #45a5cf;
	text-align: center;
}
    label input { border:0; line-height:20px; padding:0px 10px; overflow:visible; color:#fff; }
    label.ui-blue { background:#8a9cc2; border:1px solid #29447e; }
    label.ui-blue input { background:#5e77aa; }
    
    .list{
    background-image: url(tianjia.jpg);
	width: 1013px;
	height: 549px;
	margin-top:25px;
    }
    .list table{
    margin-top:150px
    }
  
    .list table input{
    background-color: #45a5cf
    }
</style>

	</head>

	<body>
		<form action="./AddDao" name="formname" method="post" >
			<div class="list" style="padding-top:50px;">
				<table align="center">
					<tr>
						<th>
							用户ID：
						</th>
						<td>
							<input type="text" name="userId" id="id" onblur="checkid();">
						</td>
						<th>
							用户姓名：
						</th>
						<td>
							<input type="text" name="username" id="name" onblur="checkname();">
						</td>
					</tr>
					<tr>
						<th>
							用户密码：
						</th>
						<td>
							<input type="text" id="pass" name="userpass" onblur="checkpass();">
						</td>
						<th>
							用户性别：
						</th>
						<td>
							<input name="sex" type="radio" value="男" checked="checked" />
							男
							<input type="radio" name="sex" value="女" />
							女
						</td>
					</tr>
					<tr>
						<th>
							用户生日：
						</th>
						<td>
							<select name="birthyear">
							<%
									for (int i = 1991; i <=2010; i++) {
								%>
								<option value="<%=i%>"><%=i%></option>
								<%
									}
								%>
							</select>
							年
							<select name="birthmonth">
								<%
									for (int i = 1; i <= 12; i++) {
								%>
								<option value="<%=i%>"><%=i%></option>
								<%
									}
								%>
							</select>
							月
							<select name="birthday">
								<%
									for (int i = 1; i <= 31; i++) {
								%>
								<option value="<%=i%>"><%=i%></option>
								<%
									}
								%>
							</select>
							日
						</td>

						<th>
							身份证 ：
						</th>
						<td>
							<input type="text" name="userCarid">
						</td>
					</tr>
					<tr>
						<th>
							用户邮箱：
						</th>
						<td>
							<input type="text" id="email" name="email" onblur="checkemail();">
						</td>
						<th>
							用户电话：
						</th>
						<td>
							<input type="text" id="phone" name="pone" onblur="checkphone();">
						</td>
					</tr>
					<tr>
						<th>
							用户地址：
						</th>
						<td>
							<input type="text" id="address" name="addres" onblur="checkaddress();">
						</td>
						<th>
							用户级别：
						</th>
						<td>
							<input type="radio" name="jibie" value="2" checked="checked">
							普通用户
						</td>
					</tr>
					<tr>
						<th>
							用户备注：
						</th>
						<td>
							<input type="text" name="beizhu">
						</td>
						<th>
							&nbsp;
						</th>
						<td>
							<input type="hidden" name="hname" value="zhuce">
						</td>
					</tr>
				</table>
			<div class="labell">
     <label class="ui-blue"><input type="submit" name="submit" value="提交" onclick="return checknum1()"/></label>
     </div>
			</div>
		</form>
	</body>
</html>
